package com.cfg;

import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author <a href="15226116300@163.com">王廷俊</a>
 * @Description
 * @Date 2024-11-12
 */
public class ServiceProxyHandler {
    
    protected Class<?> targetClass;
    
    protected Method targetMethod;
    
    protected AbstractServiceProxy serviceFirstProxy;
    
    public ServiceProxyHandler(Class<?> var1, Method var2) {
        this.targetClass = var1;
        this.targetMethod = var2;
    }
    
    public boolean hasProxy() {
        String var1 = PackageUtil.getMethodSignature(this.targetClass, this.targetMethod);
        
        try {
            this.serviceFirstProxy = (AbstractServiceProxy) EngineConfigurationImpl.getInstance()
                    .getDynamicProxyConfiguration().getFirstPorxyObject("serviceMethod", var1);
        } catch (IllegalAccessException var3) {
            throw new RuntimeException(this.targetClass.getName() + "", var3);
        } catch (InstantiationException var4) {
            throw new RuntimeException(this.targetClass.getName() + "", var4);
        }
        
        return this.serviceFirstProxy != null;
    }
    
    public Object executeProxyMethod(Object var1, Object[] var2, MethodProxy var3) {
        if (this.hasProxy()) {
            this.serviceFirstProxy.setTarget(var1);
            this.serviceFirstProxy.setTargetMethod(this.targetMethod);
            this.serviceFirstProxy.setMethodProxy(var3);
            return this.serviceFirstProxy.executeMethodForMe(var2);
        } else {
            try {
                return var3.invokeSuper(var1, var2);
            } catch (Throwable var5) {
                throw new RuntimeException(
                        var1.getClass().getName() + "." + this.targetMethod.getName() + "方法执行出错！", var5);
            }
        }
    }
}
